<script setup lang="ts">
import type { Banner, CourseBaseInfo, ResOptions, ResultIndex, ResultList, TeacherBaseInfo } from '~~/types/types'
// const courseList = ref<CourseBaseInfo[]>()
// const teacherList = ref<TeacherBaseInfo[]>()
// const bannerList = ref<Banner[]>()
const { data: info } = await useFetch('http://localhost:8080/preschool/index', {
  // @ts-ignore
  pick: ['result']
})
const { data: banner } = await useFetch('http://localhost:8080/banner', {
  // @ts-ignore
  pick: ['result']
})
const res = (info.value as ResOptions<ResultIndex>).result
const courseList = res?.courseList as CourseBaseInfo[]
const teacherList = res?.teacherList as TeacherBaseInfo[]
const bannerList = (banner.value as ResOptions<ResultList<Banner>>).result?.list as Banner[]

</script>

<template>
  <div>
    <!-- 幻灯片 开始 -->
    <Swiper :modules="[SwiperAutoplay, SwiperEffectCreative]" :slides-per-view="1" :loop="true" :effect="'creative'"
      :autoplay="{
        delay: 2000,
        disableOnInteraction: true,
      }" :creative-effect="{
  prev: {
    shadow: false,
    translate: ['-20%', 0, -1],
  },
  next: {
    translate: ['100%', 0, 0],
  },
}">
      <SwiperSlide v-for="item in bannerList" :key="item.id">
        <img :src="item.imageUrl" :title="item.title" :alt="item.title" />
      </SwiperSlide>
    </Swiper>
    <!-- 幻灯片 结束 -->

    <div id="aCoursesList">
      <!-- 网校课程 开始 -->
      <div>
        <section class="container">
          <header class="comm-title">
            <h2 class="tac">
              <span class="c-333">热门课程</span>
            </h2>
          </header>
          <div>
            <article class="comm-course-list">
              <ul id="bna" class="of">
                <li v-for="course in courseList" :key="course.id">
                  <div class="cc-l-wrap">
                    <section class="course-img">
                      <img :src="course.cover" class="img-responsive" :alt="course.title">
                      <div class="cc-mask">
                        <a :href="'/course/' + course.id" title="开始学习" class="comm-btn c-btn-1">开始学习</a>
                      </div>
                    </section>
                    <h3 class="hLh30 txtOf mt10">
                      <a :href="'/course/' + course.id" :title="course.title" class="course-title fsize18 c-333">{{
                        course.title }}</a>
                    </h3>
                    <section class="mt10 hLh20 of">
                      <span class="fr jgTag bg-green">
                        <i class="c-fff fsize12 f-fA">{{ course.price === 0 ? '免费' : course.price }}</i>
                      </span>
                      <span class="fl jgAttr c-ccc f-fA">
                        <i class="c-999 f-fA">{{ course.viewCount }}人学习</i>
                        |
                        <i class="c-999 f-fA">9634评论</i>
                      </span>
                    </section>
                  </div>
                </li>
              </ul>
              <div class="clear"></div>
            </article>
            <section class="tac pt20">
              <a href="/course" title="全部课程" class="comm-btn c-btn-2">全部课程</a>
            </section>
          </div>
        </section>
      </div>
      <!-- /网校课程 结束 -->
      <!-- 网校名师 开始 -->
      <div>
        <section class="container">
          <header class="comm-title">
            <h2 class="tac">
              <span class="c-333">名师大咖</span>
            </h2>
          </header>
          <div>
            <article class="i-teacher-list">
              <ul class="of">
                <li v-for="teacher in  teacherList " :key="teacher.id">
                  <section class="i-teach-wrap">
                    <div class="i-teach-pic">
                      <a :href='teacher.id' :title=" teacher.name ">
                        <img :alt=" teacher.name " :src=" teacher.avatar ? teacher.avatar :'https://edu-lin-110.oss-cn-chengdu.aliyuncs.com/%E5%82%B2%E5%A8%87.jpg'">
                      </a>
                    </div>
                    <div class="mt10 hLh30 txtOf tac">
                      <a :href="'/teacher/'+teacher.id" :title=" teacher.name " class="fsize18 c-666">{{ teacher.name }}</a>
                    </div>
                    <div class="hLh30 txtOf tac">
                      <span class="fsize14 c-999">{{ teacher.level === 1 ? '高级讲师' : '首席讲师' }}</span>
                    </div>
                    <div class="mt15 i-q-txt">
                      <p class="c-999 f-fA">{{ teacher.intro }}</p>
                    </div>
                  </section>
                </li>
              </ul>
              <div class="clear"></div>
            </article>
            <section class="tac pt20">
              <a href="/teacher" title="全部讲师" class="comm-btn c-btn-2">全部讲师</a>
            </section>
          </div>
        </section>
      </div>
      <!-- /网校名师 结束 -->
    </div>
  </div>
</template>
<style scoped>
.swiper {
  width: 100%;

}

.swiper-slide {
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 18px;
  height: 70vh;
  font-size: 4rem;
  font-weight: bold;
  font-family: 'Roboto', sans-serif;
}

.swiper-wrapper {
  min-width: 100vh;
  width: 100vh;
}
</style>